perf: reuse single tsx register for TS imports#248
Open
Karavil wants to merge 1 commit intorocicorp:mainfrom
Open
perf: reuse single tsx register for TS imports#248Karavil wants to merge 1 commit intorocicorp:mainfrom
Karavil wants to merge 1 commit intorocicorp:mainfrom
Conversation
tsImport() from tsx/esm/api creates a new module.register() and
MessageChannel per invocation. The CLI calls it up to 3 times. By
creating a single register({namespace}) instance and reusing its
.import() method, we eliminate redundant hook registrations.
Micro-benchmark shows ~90ms savings per additional tsImport call
(96ms for 2x tsImport vs 3ms for shared register + 2x import).
* Add src/cli/ts-import.ts with lazy shared register singleton
* Replace tsImport() in config.ts (1 call) and drizzle-kit.ts (2 calls)
7447593 to
a51fd3f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tsImport()fromtsx/esm/apicreates a freshmodule.register()+MessageChannelper call. The CLI invokes it up to 3 times (once inconfig.ts, twice indrizzle-kit.ts).register({namespace})singleton that lazily initializes on first use and reuses its.import()method for all subsequent TS file imports.tsImport= ~96ms vs shared register + 2x.import()= ~3ms (~90ms saved per extra call).Changes
src/cli/ts-import.ts: lazy singleton wrapper aroundtsxregister().src/cli/config.ts: replacetsImport()withtsImportShared().src/cli/drizzle-kit.ts: replace bothtsImport()calls withtsImportShared().Test plan
npx vitest runpasses (same pre-existing failures asmain)diffclean)